package cn.youframe.sample.db;

import cn.youframe.frame.base.BaseDaoImpl;

import java.util.List;
import java.util.Map;

/**
 * User: Administrator
 * DateTime: 12-7-22 下午2:15
 * Desc:
 */
public class DBManagerDaoImpl extends BaseDaoImpl implements DBManagerDao {
    @Override
    public int execUpdate(String sql) {
        int ret=-1;
        ret=getJdbcTemplate().update(sql);
        return ret;
    }

    @Override
    public List<String> getTables() {
        String sql="select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='PUBLIC' ORDER BY TABLE_NAME";
        return getJdbcTemplate().queryForList(sql,String.class);
    }

    @Override
    public List<Map<String,Object>> query(String sql) {
        List<Map<String,Object>> reLs=null;
        reLs=getJdbcTemplate().queryForList("select * from ("+sql+") where rownum<501");
        return reLs;
    }

    @Override
    public List<Map<String,Object>> queryTable(String sql, String tname) {
        return getJdbcTemplate().queryForList(sql,new Object[]{tname});
    }
}
